package com.wangzhen.rxjava;

import rx.Observable;
import rx.Observer;
import rx.Scheduler;
import rx.schedulers.Schedulers;

public class RxHelloWorldTest {

    public static void main(String[] args) throws InterruptedException {
        String[] words = {"hello", "worlds"};
        Observable<String> from = Observable.from(words).subscribeOn(Schedulers.io()).observeOn(Schedulers.io());

        Observer<String> observer = new Observer() {
            @Override
            public void onCompleted() {
                System.out.println(Thread.currentThread().getName()+" onCompleted()! ");
            }

            @Override
            public void onError(Throwable e) {
                System.out.println(Thread.currentThread().getName()+" onError!  ");
            }

            @Override
            public void onNext(Object o) {
                System.out.println(Thread.currentThread().getName()+" onNext-->" + o);
            }
        };

        from.subscribe(observer);
        System.out.println(Thread.currentThread().getName());
        Thread.sleep(3000);

    }
}
